#ifndef __FRAMEBUFFER
#define __FRAMEBUFFER

/*
basic definition of a variable framebuffer. RGBA in 32 bit is supported.

framebuffer pixel are ordered in the range of ([0,x-1], [0,y-1]).
coordinate (0,0) is the right upper corner.
*/

// INCLUDES -------------------------------------------------------------------------
#include "base_datatypes.h"	// datatypes: "fNumber", "bool"

// PIXEL DATATYPES ------------------------------------------------------------------
typedef struct
{
	union {
		fNumber rgba[4];	// unified variant
		struct
		{
			fNumber red,	// red component
					green,	// green component
					blue,	// blue component
					alpha;	// alpha component
		};
	};
} pixelRGBA32;

typedef void (*framebufferCallback)(unsigned int x,  // current X position
																	  unsigned int y,  // current Y position
																	  pixelRGBA32 *p); // the actual pixel at that position

// FRAMEBUFFER DATATYPES ------------------------------------------------------------
typedef enum
{
	RGBA32,					// RGB+Alpha values in floating-point
	FRAMEBUFFERTYPE_EOL
} framebufferType;

typedef enum
{
	LINE,                 // [for every line -> for every pixel of that line] top-to-bottom
	PROCESSINGTYPE_EOL
} processingType;

typedef struct
{
	framebufferType type; 	// type of the framebuffer
	void* buffer;         	// memory location of the framebuffer data
	unsigned int width,	  	// width in pixels X
	             height;  	// height in pixels Y
	framebufferCallback cb; // callback function used in framebufferProcess()
} framebuffer;

// FUNCTIONS ------------------------------------------------------------------------

// clear all memory and reset framebuffer engine
void framebufferFreeMemory();

// create a framebuffer held in memory -> RETURNS CREATED SLOT NUMBER
int framebufferCreate(framebufferType type,	// type of framebuffer data
					  unsigned int width,	// width in pixels X
					  unsigned int height);	// height in pixels Y

// register a function callback for framebufferProcess() to work with
void framebufferRegisterCallback(unsigned int slot,       // slot id of an existing framebuffer
                                 framebufferCallback cb); // callback function for framebufferProcess()

// process the framebuffer and call a registered callback
void framebufferProcess(unsigned int slot,
                        processingType type);

// retrieve raw access to a framebuffer that was previously created
framebuffer* framebufferGetFramebuffer(unsigned int slot);

#endif // __FRAMEBUFFER
